<?php

/**
 * 广告相关接口
 */
class a_ad extends CI_Controller {

    function __construct() {
        parent::__construct();
    }

    /**
     * 广告列表 分页
     * @param int $adpositionid 广告位置id
     * @param int $page 当前页数
     * @param int $limit 显示数量
     * @return array 
     */
    function get_ad_list_page($adpositionid = 0, $page = 1, $limit = 10) {
        $where = array(
            'ad.isclose' => 0
        );
        if ($adpositionid > 0) {
            $where['ad.adpositionid'] = $adpositionid;
        }
        $data = array(
            'from' => 'ad',
            'column' => 'ad.adid,ad.adname,ad.adsmallpic,ad.adpath,ad.adlink',
            'where' => $where,
            'order' => 'ad.listid asc',
        );
        $result = $this->m_public->get_list_page($data, $page, $limit);
        return $result;
    }

    /**
     * 广告列表
     * @param int $adpositionid 广告位置id
     * @param int $limit 显示数量
     * @return array 
     */
    function get_ad_list($adpositionid = 0, $limit = 10) {
        $where = array(
            'ad.isclose' => 0
        );
        if ($adpositionid > 0) {
            $where['ad.adpositionid'] = $adpositionid;
        }
        $data = array(
            'from' => 'ad',
            'column' => 'ad.adid,ad.adname,ad.adsmallpic,ad.adpath,ad.adlink',
            'where' => $where,
            'order' => 'ad.listid desc',
            'offset' => 0,
            'limit' => $limit,
        );
        $result = $this->m_public->get_list($data, $page, $limit);
        return $result;
    }

    /**
     * 获取广告位
     * @param int $adpositionid 广告位id
     * @return array
     */
    function get_adposition($adpositionid) {
        $data = array(
            'adpositionid' => $adpositionid,
        );
        return $this->m_public->getRowInfo('adposition', $data);
    }

}
